import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '首页',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index')
    }]
  },
  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [

  {
    path: '/house',
    component: Layout,
    redirect: '/house/desc',
    name: 'house',
    meta: { title: '出租房源', icon: 'example' ,roles: ['admin', 'house','agent']},
    children: [
      { path: 'desc', name: 'desc', hidden:true,component: () => import('@/views/table/desc'), meta: { title: '房源描述', icon: 'table' }},
      { path: 'product', name: 'product', hidden:true, component: () => import('@/views/table/product'), meta: { title: '房源配套', icon: 'table' }},
      { path: 'report', name: 'report', component: () => import('@/views/table/report'), meta: { title: '房源举报', icon: 'table' }},
      { path: 'cost', name: 'cost', component: () => import('@/views/table/cost'), meta: { title: '租金管理', icon: 'table' }},
      { path: 'house', name: 'house', component: () => import('@/views/table/house'), meta: { title: '租房列表', icon: 'table' ,roles: ['admin','house']}},
      { path: 'contract', name: 'contract', component: () => import('@/views/table/contract'), meta: { title: '合同管理', icon: 'table' ,roles: ['admin','house']}},
      { path: 'resource', name: 'resource', component: () => import('@/views/table/resource'), meta: { title: '房源列表', icon: 'table' }}
    ]
  },
  {
    path: '/newhouse',
    component: Layout,
    redirect: '/newhouse/table',
    name: 'newhouse',
    meta: { title: '楼盘管理', icon: 'example' ,roles: ['admin', 'house','agent']},
    children: [
      { path: 'newhouse', name: 'newhouse', component: () => import('@/views/table/newhouse'), meta: { title: '楼盘信息', icon: 'table',roles: ['admin','agent'] }},
      { path: 'newhousemap', name: 'newhousemap', component: () => import('@/views/table/newhousemap'), meta: { title: '楼盘分布', icon: 'table',roles: ['admin','agent'] }}
    ]
  },
  {
    path: '/oldhouse',
    component: Layout,
    redirect: '/oldhouse/table',
    name: 'oldhouse',
    meta: { title: '二手房源', icon: 'example' },
    children: [
      { path: 'oldhouse', name: 'oldhouse', component: () => import('@/views/table/oldhouse'), meta: { title: '二手房源', icon: 'table' ,roles: ['admin','agent']}},
      { path: 'oldhousemap', name: 'oldhousemap', component: () => import('@/views/table/oldhousemap'), meta: { title: '房源分布', icon: 'table',roles: ['admin','agent'] }}
    ]
  },
  {
    path: '/rent',
    component: Layout,
    redirect: '/rent/table',
    name: 'rent',
    meta: { title: '看房请求', icon: 'example' },
    children: [
      { path: 'request', name: 'request', component: () => import('@/views/table/request'), meta: { title: '看房请求', icon: 'table' ,roles: ['admin','house']}}
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/table',
    name: 'Example',
    meta: { title: '用户管理', icon: 'example' },
    children: [
      { path: 'client', name: 'client', component: () => import('@/views/table/client'), meta: { title: '委托人管理', icon: 'table',roles: ['admin','house'] }},
      { path: 'information', name: 'information', component: () => import('@/views/table/information'), meta: { title: '经纪人信息', icon: 'table' ,roles: ['admin']}},
      { path: 'rent', name: 'rent', component: () => import('@/views/table/rent'), meta: { title: '租户管理', icon: 'table' ,roles: ['admin']}},
      { path: 'user', name: 'table', component: () => import('@/views/table/user'), meta: { title: '用户管理', icon: 'table' ,roles: ['admin']}}
    ]
  },
  {
    path: '/area',
    component: Layout,
    redirect: '/area/index',
    name: 'area',
    meta: { title: '房源分布', icon: 'example' },
    children: [
      { path: 'area', name: 'area', component: () => import('@/views/area/index'), meta: { title: '房源分布', icon: 'table' ,roles: ['admin']}}
    ]
  },
  {
    path: '/chat',
    component: Layout,
    redirect: '/chat/index',
    name: 'chat',
    meta: { title: '在线咨询', icon: 'example' },
    children: [
      { path: 'chat', name: 'chat', component: () => import('@/views/chat/index'), meta: { title: '在线咨询', icon: 'table' ,roles: ['admin','agent']}}
    ]
  },
  { path: '*', redirect: '/404', hidden: true }]
